module.exports = {
	/**
	 * 添加单条数据
	 * @url admin/kong/sys/add 前端调用的url参数地址
	 * data 请求参数 说明
	 * res 返回参数说明
	 * @param {Number} code 错误码，0表示成功
	 * @param {String} msg 详细信息
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			dbName
		} = data;
		let res = {
			code: 0,
			msg: 'ok'
		};
		// 业务逻辑开始-----------------------------------------------------------
		// delete data.uid
		// 这里需要把 params1 params2 params3 改成你数据库里允许用户添加的字段
		let order_id =  getWxPayOrdrID()
		data.platform = originalParam.context.PLATFORM
		await vk.baseDao.add({
			dbName: "wx_order",
			dataJson: {
				status:0,
				order_id:order_id,
				...data
			}
		});
		res.order_id = order_id
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}


/* 商户订单编号*/
function getWxPayOrdrID() {
	var myDate = new Date();
	var year = myDate.getFullYear();
	var mouth = myDate.getMonth() + 1;
	var day = myDate.getDate();
	var hour = myDate.getHours();
	var minute = myDate.getMinutes();
	var second = myDate.getSeconds();
	var msecond = myDate.getMilliseconds(); //获取当前毫秒数(0-999)
	if (mouth < 10) {
		/*月份小于10  就在前面加个0*/
		mouth = String(String(0) + String(mouth));
	}
	if (day < 10) {
		/*日期小于10  就在前面加个0*/
		day = String(String(0) + String(day));
	}
	if (hour < 10) {
		/*时小于10  就在前面加个0*/
		hour = String(String(0) + String(hour));
	}
	if (minute < 10) {
		/*分小于10  就在前面加个0*/
		minute = String(String(0) + String(minute));
	}
	if (second < 10) {
		/*秒小于10  就在前面加个0*/
		second = String(String(0) + String(second));
	}
	if (msecond < 10) {
		msecond = String(String(0) + String(second));
	} else if (msecond >= 10 && msecond < 100) {
		msecond = String(String(0) + String(second));
	}

	var currentDate =
		String(year) +
		String(mouth) +
		String(day) +
		String(hour) +
		String(minute) +
		String(second) +
		String(msecond);
	return 'ai_' + currentDate;
}